package services

import (
	"jlpay-sdk-go/pkg/jlpay/core"
	"jlpay-sdk-go/pkg/jlpay/models"
)

// ClearingService 清算服务
type ClearingService struct {
	*BaseService
}

// NewClearingService 创建清算服务
func NewClearingService(config *core.Config) *ClearingService {
	return &ClearingService{
		BaseService: NewBaseService(config),
	}
}

// QueryWithdraw 查询提现结果
func (s *ClearingService) QueryWithdraw(request *models.WithdrawQueryRequest) (*models.WithdrawQueryResponse, error) {
	response := models.NewWithdrawQueryResponse()

	// 设置API路径
	apiPath := "/fund/withdraw/query"

	// 发送请求
	err := s.Post(request, response, apiPath)
	if err != nil {
		return nil, err
	}

	return response, nil
}

// ApplyWithdraw 申请提现
func (s *ClearingService) ApplyWithdraw(request *models.WithdrawApplyRequest) (*models.WithdrawApplyResponse, error) {
	response := models.NewWithdrawApplyResponse()

	// 设置API路径
	apiPath := "/fund/withdraw/apply"

	// 发送请求
	err := s.Post(request, response, apiPath)
	if err != nil {
		return nil, err
	}

	return response, nil
}

// UploadVideo 上传视频文件
func (s *ClearingService) UploadVideo(request *models.FileUploadRequest) (*models.FileUploadResponse, error) {
	response := models.NewFileUploadResponse()

	// 设置API路径
	apiPath := "/base/file/upload/video"

	// 发送请求
	err := s.Post(request, response, apiPath)
	if err != nil {
		return nil, err
	}

	return response, nil
}

// QueryAccBalance 查询结算资金
func (s *ClearingService) QueryAccBalance(request *models.AccBalanceRequest) (*models.AccBalanceResponse, error) {
	response := models.NewAccBalanceResponse()

	// 设置API路径
	apiPath := "/fund/settlement/account/balance"

	// 发送请求
	err := s.Post(request, response, apiPath)
	if err != nil {
		return nil, err
	}

	return response, nil
}

// ParseNotify 解析通知消息
func (s *ClearingService) ParseNotify(notifyData map[string]interface{}) *models.NotifyDto {
	return models.NewNotifyDto(notifyData)
}
